package com.example.controller;

import com.example.entity.SecKillSku;
import com.example.entity.SecKillSpu;
import com.example.service.SkuService;
import com.example.service.SpuService;
import com.example.vo.ResponseVO;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @Author 游家纨绔
 * @Description TODO
 * @Date 2025-05-21 10:00:00
 */
@Controller
@RequestMapping("/goods")
public class GoodsController {

	/**
	 * 服务对象
	 */
	@Autowired
	private SpuService spuService;
	@Autowired
	private SkuService skuService;


	@PostMapping("transformGood")
	@ResponseBody
	public ResponseVO changeGood(Integer spuId, String color) {
		SecKillSku sku = skuService.changeGoodByColor(spuId, color);
		return ResponseVO.success(200, sku, "查询成功");
	}

	@GetMapping("getGoods")
	public String getGoods(Integer id, Model model) {
		SecKillSpu secKillSpu = spuService.selectOne(id);
		SecKillSku secKillSku = skuService.queryMinPriceSku(id);
		List<String> color = skuService.selectColor(id);
		model.addAttribute("spu", secKillSpu);
		model.addAttribute("sku", secKillSku);
		model.addAttribute("color", color);
		return "goods";
	}

}
